var http = require("../../../utils/httpUtils.js")
var app = getApp()
Page({

  data: {
    currentData: 0,
    selectPerson: true,
    selectToDelete: false,
    selectCount: 0,
    activityData: [],
    courseData: [],
    campusData:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '我的收藏',
    })
    this.getData()
  },
  getData:function(){
    http.G(app.globalData.SERVER_IP +'/user/organizationActivityCollect/u_id/'+wx.getStorageSync('userInfo').userid+'/skip/0/limit/20',{},(res)=>{
      let informationData = res.result
      console.log(informationData)
			this.setData({
        activityData: informationData
      })
		},(err)=>{
			console.log("error:")
			console.log(err)
    })
    http.G(app.globalData.SERVER_IP +'/user/organizationCourseCollect/u_id/'+wx.getStorageSync('userInfo').userid+'/skip/0/limit/20',{},(res)=>{
      let informationData = res.result
      console.log(informationData)
			this.setData({
        courseData: informationData
      })
		},(err)=>{
			console.log("error:")
			console.log(err)
		})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.hideShareMenu({
		})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindchange: function (e) {
    this.setData({
      currentData: e.detail.current
    })
  },
  checkCurrent: function (e) {
    const that = this;
    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentData: e.target.dataset.current
      })
      this.selectCancle()
    }
  },
  select_item_to_delete: function () {
    this.setData({
      selectToDelete: !this.data.selectToDelete
    })
    this.selectCancle()
  },
  //删除课程
  select_course_item: function (e) {
    var temp = "courseData[" + e.currentTarget.dataset.index + "].isDelete"
    this.setData({
      [temp]: !this.data.courseData[e.currentTarget.dataset.index].isDelete
    })
    var count = 0;
    for (var i = 0; i < this.data.courseData.length; i++) {
      if (this.data.courseData[i].isDelete) {
        count++;
      }
    }
    this.setData({
      selectCount: count
    })
  },
  //删除活动
  select_activity_item: function (e) {
    var temp = "activityData[" + e.currentTarget.dataset.index + "].isDelete"
    this.setData({
      [temp]: !this.data.activityData[e.currentTarget.dataset.index].isDelete
    })
    var count = 0;
    for (var i = 0; i < this.data.activityData.length; i++) {
      if (this.data.activityData[i].isDelete) {
        count++;
      }
    }
    this.setData({
      selectCount: count
    })
  },
  //删除校区
  select_campus_item: function (e) {
    var temp = "campusData[" + e.currentTarget.dataset.index + "].isDelete"
    this.setData({
      [temp]: !this.data.campusData[e.currentTarget.dataset.index].isDelete
    })
    var count = 0;
    for (var i = 0; i < this.data.campusData.length; i++) {
      if (this.data.campusData[i].isDelete) {
        count++;
      }
    }
    this.setData({
      selectCount: count
    })
  },
  selectCancle:function(){
    this.setData({
      selectCount: 0
    })
    for (var i = 0; i < this.data.courseData.length; i++) {
      if (this.data.courseData[i].isDelete) {
        var temp = "courseData[" + i + "].isDelete"
        this.setData({
          [temp]: false
        })
      }
    }
    for (var i = 0; i < this.data.activityData.length; i++) {
      if (this.data.activityData[i].isDelete) {
        var temp = "activityData[" + i + "].isDelete"
        this.setData({
          [temp]: false
        })
      }
    }
    for (var i = 0; i < this.data.campusData.length; i++) {
      if (this.data.campusData[i].isDelete) {
        var temp = "campusData[" + i + "].isDelete"
        this.setData({
          [temp]: false
        })
      }
    }
  },
  	// 课程点击
	courseBtn: function (e) {
		console.log(e.target.dataset.id)
		wx.navigateTo({
			url: '../../activity/course/course?activityId=' + e.currentTarget.dataset.id + '&o_id=692',
		})
	},

	// 热门活动点击
	activityBtn: function (e) {
		console.log(e.target.dataset.id)
		wx.navigateTo({
			url: '../../activity/promotion/promotion?activityId=' + e.currentTarget.dataset.id + '&o_id=692',
		})
  },
  courseBtn: function (e) {
		console.log(e.target.dataset.id)
		wx.navigateTo({
			url: '../../activity/course/course?activityId=' + e.currentTarget.dataset.oc_id + '&o_id=692',
		})
	},
})